﻿<%@ Page Language="c#" CodeBehind="Compose.aspx.cs" AutoEventWireup="false" Inherits="UDS.SubModule.UnitiveDocument.Mail.ComposePage" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
  <title>写新邮件</title>
  <uds:Style runat="server" Href="~/css/BasicLayout.css" />
  <script language="javascript" type="text/javascript">
  //<!--
  var popWinOptions = "location=no, menubar=no, resizable=no, status=yes, titlebar=no, toolbar=no";
  var popWinName = "__OA_MAIL_POPUP";

  function SetData(data) {
    /*
    * The arguments should look like:
    *  [
    *    [[real name, username], [real name, username], ...], // to list
    *    [[real name, username], [real name, username], ...], // cc list
    *    [[real name, username], [real name, username], ...], // bcc list
    *  ]
    */
    var fnJoinArray = function(list) {
      var realNameList = "";
      var userNameList = "";
      var firstItem = true;
      if (list != null && list.length > 0) {
        for (var i = 0; i < list.length; i++) {
          if (!firstItem) {
            realNameList += ";";
            userNameList += ";";
          }
          else {
            firstItem = false;
          }

          realNameList += list[i][0];
          userNameList += list[i][1];
        }
      }

      return [realNameList, userNameList];
    };

    if (data != null && data.length === 3) {
      var tbTo = document.getElementById("<%= txtSendTo.ClientID %>");
      var tbCc = document.getElementById("<%= txtCC.ClientID %>");
      var tbBcc = document.getElementById("<%= txtBCC.ClientID %>");
      var hfTo = document.getElementById("<%= hfSendTo.ClientID %>");
      var hfCc = document.getElementById("<%= hfCC.ClientID %>");
      var hfBcc = document.getElementById("<%= hfBCC.ClientID %>");

      // TO list
      var r = fnJoinArray(data[0]);
      tbTo.value = r[0];
      hfTo.value = r[1];

      // CC list
      r = fnJoinArray(data[1]);
      tbCc.value = r[0];
      hfCc.value = r[1];

      // BCC list
      r = fnJoinArray(data[2]);
      tbBcc.value = r[0];
      hfBcc.value = r[1];
    }
  }

  function showUserPicker(type) {
    var rnd = Math.random();
    var w = window.open("SelectReceiver.aspx?ClassID=<%= ClassID %>&type=" + type + "&.rnd=" + rnd, popWinName, "height=500, width=600, " + popWinOptions);
  }

  function showProjectChooser() {
    var rnd = Math.random();
    var ret = window.showModalDialog("TreeView.aspx" + "&.rnd=" + rnd, window, "dialogHeight:400px;dialogWidth:300px;" + popWinOptions);
    return (ret > 0);
  }

  function focusNextLink(elm) {
    while (elm) {
      elm = elm.nextSibling;
      if (elm && elm.nodeTye == /* element, not text */1 && (elm.tagName === "A" || elm.tagName === "a")) {
        elm.focus();
        break;
      }
    }
  }
  //-->
  </script>
</head>
<body>
  <form runat="server">
  <%--These hidden fields will be used for storing the names of the selected users.--%>
  <asp:HiddenField runat="server" ID="hfSendTo" />
  <asp:HiddenField runat="server" ID="hfCC" />
  <asp:HiddenField runat="server" ID="hfBCC" />
  <uds:PageTitle runat="server" Title="我的邮件" HintImage="~/Images/icon/284.GIF" />
  <div>
    <table cellpadding="0" cellspacing="0" border="0" width="100%">
      <tr>
        <td class="unselectedTab">
          <a href="Index.aspx?FolderType=<%= (int)MailFolderType.Index %>" class="Newbutton">收件箱</a>
        </td>
        <td class="unselectedTab">
          <a href="Index.aspx?FolderType=<%= (int)MailFolderType.Outbox %>" class="Newbutton">发件箱</a>
        </td>
        <td class="unselectedTab">
          <a href="Index.aspx?FolderType=<%= (int)MailFolderType.RecyleBin %>" class="Newbutton">废件箱</a>
        </td>
        <td class="selectedTab">
          <a href="Compose.aspx?ClassID=0" class="Newbutton">撰写新邮件</a>
        </td>
        <td align="right">
          &nbsp;
        </td>
      </tr>
      <tr>
        <td colspan="5" style="background-color: #93bee2; height: 5px; line-height: 5px;">
          &nbsp;
        </td>
      </tr>
    </table>
  </div>
  <table cellspacing="0" cellpadding="0" width="100%" border="0" class="formtable">
    <tr>
      <td width="100" class="formlabel">
        收件人:
      </td>
      <td>
        <asp:TextBox runat="server" ID="txtSendTo" Width="400px" ReadOnly="true" ToolTip="请点击右边的链接选择收件人" onclick="focusNextLink(this);" onfocus="focusNextLink(this);" />
        <a style="cursor: hand" onclick="showUserPicker(1)" href="javascript:void(0);">选择收件人</a>
      </td>
    </tr>
    <tr>
      <td class="formlabel">
        抄送:
      </td>
      <td>
        <asp:TextBox runat="server" ID="txtCC" Width="400px" ReadOnly="true" ToolTip="请点击右边的链接选择抄送人" onclick="focusNextLink(this);" onfocus="focusNextLink(this);" />
        <a style="cursor: hand" onclick="showUserPicker(2)" href="javascript:void(0);">选择抄送人</a>
      </td>
    </tr>
    <tr>
      <td class="formlabel">
        秘密抄送:
      </td>
      <td>
        <asp:TextBox runat="server" ID="txtBCC" Width="400px" ReadOnly="true" ToolTip="请点击右边的链接选择密送人" onclick="focusNextLink(this);" onfocus="focusNextLink(this);" />
        <a style="cursor: hand" onclick="showUserPicker(2)" href="javascript:void(0);">选择密送人</a>
      </td>
    </tr>
    <tr>
      <td class="formlabel">
        主&nbsp;&nbsp;题:
      </td>
      <td>
        <asp:TextBox ID="txtSubject" runat="server" CssClass="InputCss" Width="484px" />
      </td>
    </tr>
    <tr>
      <td class="formlabel">
        重要性:
      </td>
      <td>
        <uds:MailImportanceDropDownList runat="server" ID="ddlImportance" />
        &nbsp;&nbsp;&nbsp;&nbsp;
        <%--
        TODO: DO NOT allow to choose project for now.
        <input class="InputCss" name="hdnProjectID" style="width: 150px; height: 20px" type="hidden" size="11" value="<%=ClassID %>" width="20" />
        <input class="InputCss" name="txtProjectName" style="width: 150px; height: 20px" readonly type="text" size="11" value="<%=GetClassName() %>" width="20" />
        <input class="redButtonCss" onclick="showProjectChooser()" type="button" value="▼" />
        --%>
        <asp:CheckBox ID="cbRemind" runat="server" Text="站内短消息提醒" />
        <asp:CheckBox ID="cbSMS" runat="server" Text="手机短消息提醒" />
      </td>
    </tr>
    <tr>
      <td class="formlabel">
        内&nbsp;&nbsp;容:
      </td>
      <td>
        <asp:TextBox ID="txtBody" runat="server" CssClass="inputsta" Width="486px" Height="188px" TextMode="MultiLine" />
      </td>
    </tr>
    <tr>
      <td class="formlabel">
        附&nbsp;&nbsp;件:
      </td>
      <td>
        <uds:FileUploader runat="server" ID="fileUploader" MaxFileCount="10" />
      </td>
    </tr>
    <tr class="InputCss">
      <td>
        &nbsp;
      </td>
      <td>
        <p>
          <%--TODO: hide the checkboxlist for now. --%>
          <asp:CheckBoxList ID="cblistAttribute" runat="server" RepeatDirection="Horizontal" Visible="false" />
        </p>
        <p>
          <script type="text/javascript">
          //<!--
          // var referrer = document.referrer;
          var referer = "<%= Request.UrlReferrer %>";
          function EndComposeMail() {
            try {
              if (parent.frames.length == 0)
                window.close();
              else
                self.location = referer;
            } catch (e) { }
          }
          //-->
          </script>
          <asp:Button ID="btnSendMail" runat="server" CssClass="ButtonCss" Text=" 发  送 " />
          <input class="ButtonCss" style="width: 58px; height: 20px" onclick="javascript:EndComposeMail();" type="button" value=" 返  回 " />
        </p>
      </td>
    </tr>
  </table>
  </form>
</body>
</html>
